package com.wq.data.redpacket.repository;


import com.wq.api.domain.entity.redpacket.RedPacketAccount;
import com.wq.api.exception.InsufficientBalanceException;
import com.wq.api.repository.redpacket.RedPacketAccountRepository;
import com.wq.data.redpacket.dao.RedPacketAccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created by changming.xie on 4/2/16.
 */
@Repository
public class RedPacketAccountRepositoryImpl implements RedPacketAccountRepository {

    @Autowired
    RedPacketAccountMapper redPacketAccountMapper;

    @Override
    public RedPacketAccount findByUserId(long userId) {

        return redPacketAccountMapper.findByUserId(userId);
    }

    @Override
    public void save(RedPacketAccount redPacketAccount) {
        int effectCount = redPacketAccountMapper.update(redPacketAccount);
        if (effectCount < 1) {
            throw new InsufficientBalanceException();
        }
    }
}
